﻿using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RedisPublishSubscribe
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var value = Console.ReadLine();

                Publish1(value);
            }

            Console.Read();
        }

        public static void Publish1(string msg)
        {
            using (RedisClient client = new RedisClient("139.224.232.51", 6379, "Aa111111"))
            {
                string message = "订单ID：20315308"+ msg;
                if (msg.Contains("1"))
                {
                    client.PublishMessage("channel1", message);
                }

                if (msg.Contains("2"))
                {
                    client.PublishMessage("channel2", message);
                }

                Console.WriteLine("消息发布成功");
            }
        }

        public static void Publish()
        {
            ////PooledRedisClientManager
            //IRedisClientsManager redisClientManager = new PooledRedisClientManager("127.0.0.1:6379");
            ////发布、订阅服务 IRedisPubSubServer
            //RedisPubSubServer pubSubServer = new RedisPubSubServer(redisClientManager, "channel1")
            //{
            //    OnMessage = (channel, msg) =>
            //    {
            //        Console.WriteLine($"从频道：{channel}上接受到消息：{msg},时间：{DateTime.Now.ToString("yyyyMMdd HH:mm:ss")}");
            //        Console.WriteLine("___________________________________________________________________");
            //    },
            //    OnStart = () =>
            //    {
            //        Console.WriteLine("发布服务已启动");
            //        Console.WriteLine("___________________________________________________________________");
            //    },
            //    OnStop = () => { Console.WriteLine("发布服务停止"); },
            //    OnUnSubscribe = channel => { Console.WriteLine(channel); },
            //    OnError = e => { Console.WriteLine(e.Message); },
            //    OnFailover = s => { Console.WriteLine(s); },
            //};
            ////接收消息
            //pubSubServer.Start();
        }


    }
}
